# encoding: utf-8
"""
Serialization schemas for Zones resources RESTful API
----------------------------------------------------
"""

from flask_marshmallow import base_fields
from flask_restplus_patched import ModelSchema
from app.modules.common.schemas import BaseSchema
from .models import App

class BaseAppsSchema(ModelSchema):
    """
    Base team schema exposes only the most general fields.
    """

    class Meta:
        # pylint: disable=missing-docstring
        model = App
        fields = (
            App.app_id.key,
            App.zone_code.key,
            App.app_name.key,
            App.port.key,
            App.app_type.key,
            App.db_type.key,
            App.db_name.key,
            App.status.key,
            App.db_status.key,
            App.version.key,
            App.on_beetle.key,
            App.mem_level.key,
            App.last_msg.key,
            App.app_install_date.key,
            App.db_import_date.key,
            App.app_package_create_date.key,
            App.db_dump_create_date.key,
            App.disabled.key,
            App.starting_order.key,
            'is_running',
            'running_pipeline',
        )

        dump_only = (
            App.app_id.key,
        )

class AppListSchema(BaseSchema):
    data = base_fields.Nested(
        BaseAppsSchema,
        many = True
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )

